package com.lcy.lambda.function;

import lombok.Data;

import java.io.File;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.function.BiPredicate;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;

/**
 * 该案例是用来测试，当一个方法的参数是接口时，外层调用如果用到了某个另外的实例，该如何处理。
 * @author lcy
 * @date 2024/8/22 11:38
 */
public class Test {



    public static void main(String[] args) {

//        Function<String, Integer> lambda1 =  s -> Integer.parseInt(s);

        Function<String, Integer> lambda1 =  Integer::parseInt;
        System.out.println(lambda1.apply("123"));

//        BiPredicate<List<String>, String> lambda2 =  (list, element) -> list.contains(element);
        BiPredicate<List<String>, String> lambda2 = List::contains;
        System.out.println(lambda2.test(Arrays.asList("1", "2", "3"), "1"));


//        BiPredicate<Student, Student> lambda3 =  (stu, o) -> stu.equals(o);
//        Test.Student student = new Test.Student();
        BiPredicate<Student, Student> lambda3= Student::equals;
//        System.out.println(lambda3.test(new Student(), new Student()));


//        Predicate<File> lambda4 = file -> file.exists();
        Predicate<File> lambda4 = File::exists;
        System.out.println(lambda4.test(new File("C:\\Users\\67304\\Desktop\\会员智能信息推送系统开发需求文档")));

        Runtime runtime = Runtime.getRuntime();
        //Supplier<Long> lambda5 = () -> runtime.freeMemory();
        Supplier<Long> lambda5 = runtime::freeMemory;
        System.out.println(lambda5.get());


        Function<Integer, Integer> fun = x -> x * x;
        System.out.println(fun.apply(3));

        int y = 3;
        Function<Integer, Integer> fun2 = x -> x * y;
        System.out.println(fun2.apply(3));

    }

    @Data
    static class Student{
        private String name;
        private Integer age;

//        @Override
//        public boolean equals(Object o) {
//            if (this == o) return true;
//            if (o == null || getClass() != o.getClass()) return false;
//            Student student = (Student) o;
//            return Objects.equals(name, student.name) && Objects.equals(age, student.age);
//        }
    }
}
